package Test2;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-05-13
 * Time: 15:07
 */
public class SendTask implements Runnable{
    private int sendPort;
    public SendTask(int sendPort){
        this.sendPort=sendPort;
    }
    @Override
    public void run() {
        try{
            DatagramSocket ds=new DatagramSocket();
            Scanner sc=new Scanner(System.in);
            while(true){
                String data=sc.nextLine();
                byte[] buf=data.getBytes();
                DatagramPacket  dp=new DatagramPacket(buf,buf.length, InetAddress.getByName("127.0.0.255"),sendPort);
                ds.send(dp);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
